#ifndef SERVERMAP_HPP
#define SERVERMAP_HPP

#include <boost/any.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <map>
#include <string>
#include <sys/time.h>
#include "transport_interface.hpp"
#include <boost/thread.hpp>
#include <boost/signals2/mutex.hpp>

namespace pipc
{

class ServerMap : public TransportInterface
{
public:
    ServerMap(std::string ip, int port, std::string id);
    ~ServerMap();
    bool setValue(std::string key, Record value);
    Record getValue(std::string key);
    bool isSynced(std::string key);
    bool subscibe(std::string key, bool reader);
    bool isRunning();
    void clear();

    bool start();
    bool stop();

private:
    void markRecieved_(std::string key);
    std::map <std::string, Record > settings_;
    std::map <std::string, bool> marks_;
    std::map <std::string, bool> ack_;
    boost::shared_mutex serializer_;

    int port_;
    std::string ip_;
    std::string id_;
    int sockfd_;

    bool running_;
    boost::thread *listener_;

    void start_();
};

}
#endif // SERVERMAP_HPP
